package cn.itcast.sink;

import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author KTL
 * @version V1.0
 * @Package cn.itcast.sink
 * @date 2021/2/24 0024 17:13
 * @Copyright © 2015-04-29  One for each, and two for each
 *                  演示DataSream-sink基于控制台和文件
 */
public class SinkDemo01 {
    public static void main(String[] args) throws Exception {
        //TODO 0.env
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);
        //TODO 1.source
        final DataStreamSource<String> ds = env.readTextFile("data/words.txt");
        //TODO 2.transfromation
        //TODO 3.sink
        ds.print("输出标识");
        ds.printToErr();//在控制台以红色输出
        ds.writeAsText("data/output/result1").setParallelism(1);
        ds.writeAsText("data/output/result2").setParallelism(2);
        //TODO 4.excute
        env.execute();
    }
}
